home *** CD-ROM | disk | FTP | other *** search
- Path: netnews.jhuapl.edu!usenet
- From: "Daniel J. Levine" <einstein@universe.jhuapl.edu>
- Newsgroups: comp.lang.c++
- Subject: [Q] Heirarchies and Comparison Operators...
- Date: Wed, 07 Feb 1996 13:46:54 -0500
- Organization: Johns Hopkins University Applied Physics Laboratory
- Message-ID: <3118F39E.6916@universe.jhuapl.edu>
- NNTP-Posting-Host: f2ahp2.jhuapl.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.05 9000/735)
-
- I've been trying (to no avail) to think of a good way to
- solve the following problem:
-
- If you have a class heirarchy like this:
-
-
- class point
- {
- }
-
- class point1D : public point
- {
- private:
- int x;
- }
-
- class point2D : public point1D
- {
- private:
- int y;
- }
-
- class point3D : public point2D
- {
- private:
- int z;
- }
-
- I would now like to add operator==() and operator!=() to this heirarchy
- with the following meaning criteria for being equal:
-
- 1. You should be able to compare any of the 3 types (and pointers to
- them)
- and get the same results when the type is on the left or the right
- hand
- side of the operator.
-
- 2. I don't have a compiler with RTTI, but I'd like to make comparisons
- between different types to be not equal. I didn't want to use a
- magic constant for each type if it was avoidable.
-
- 3. If all the dimensions have the exact same values, they are equal.
-
- I was playing with a solution which looked like this:
-
- virtual int point::operator==(const point& rhs) = 0;
-
- virtual int point1D::operator==(const point& rhs)
- {
- // what would I put in here?
- }
-
- virtual int point2D::operator==(const point& rhs)
- {
- // and here?
- }
-
- virtual int point3D::operator==(const point& rhs)
- {
- // and here?
- }
-
-
- Any help would be greatly appreciated!
-
- -Dan
-